import axios from 'axios'
// 创建axios实例
const service = axios.create({
  baseURL: process.env.BASE_API // api 的 base_url
  // timeout: 50000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
    this.$vux.loading.hide()
  }
)

// response 拦截器
service.interceptors.response.use(
  response => {
    const res = response.data
    // alert(JSON.stringify(res))
    if (res.code !== 1) {
      // console.log('code == 0') // for debug
      // return Promise.reject(new Error(res.msg))
    }
    return response.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default service
